package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;

import com.itheima.constant.MessageConstant;
import com.itheima.domain.Menu_management;
import com.itheima.domain.PageResult;
import com.itheima.domain.QueryPageBean;
import com.itheima.domain.Result;
import com.itheima.service.Menu_managementService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;

@Controller
@RequestMapping("/menu")
@ResponseBody
public class Menu_managementController {
    @Reference
    private Menu_managementService menu_managementService;

    @RequestMapping("/findAll")
    public List<Menu_management> findAll(){
        return menu_managementService.findAll();
    }


    @RequestMapping("/EstimateFindAll")
    public List<Menu_management> EstimateFindAll(){
        return menu_managementService.EstimateFindAll();
    }

    @RequestMapping("/save")
    public void save(@RequestBody Menu_management menu_management ){
        menu_managementService.save(menu_management);
    }

    //删除
    @RequestMapping("/delete")
    public Result delete(Integer id){
        try {
            menu_managementService.delete(id);
        }catch (RuntimeException e){
            return new Result(false,e.getMessage());
        }catch (Exception e){
            return new Result(false, MessageConstant.DELETE_CHECKITEM_FAIL);
        }return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }


    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = menu_managementService.pageQuery(
                    queryPageBean.getCurrentPage(),
                    queryPageBean.getPageSize(),
                    queryPageBean.getQueryString());
        return pageResult;
    }

    //编辑
    @RequestMapping("/edit")
    public Result edit(@RequestBody Menu_management menu_management){
        try {
            menu_managementService.edit(menu_management);
        }catch (Exception e){
            return new Result(false,MessageConstant.EDIT_CHECKITEM_FAIL);
        }
        return new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }
    @RequestMapping("/findById")
    public Menu_management findById(Integer id){
            Menu_management menu_management = menu_managementService.findById(id);
            return menu_management;
    }

    @RequestMapping("/updateMenu")
    public void updateMenu(Menu_management menu_management){
        menu_managementService.updateMenu(menu_management);
    }
}
